//
//  SettingViewController.m
//  wtshoppingcite
//
//  Created by TW on 14-10-24.
//  Copyright (c) 2014年 TW. All rights reserved.
//

#import "SettingViewController.h"
#import "ReadingViewController.h"
#import "AppDelegate.h"
#import "AboutViewController.h"
#import "LoginViewController.h"

@interface SettingViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    UITableView *settingTableView;
}
@property(retain,nonatomic)NSArray *dataArray;

@end

@implementation SettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    [self setTitleView:@"设置"];
    
    _dataArray = @[@"推送通知",@"关于"];
//     _dataArray = @[@"推送通知",@"欢迎页",@"用后感",@"支付帮助",@"关于"];
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kWidth, 250)];
    [self.view addSubview:view];
    
    settingTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kWidth, 250) style:UITableViewStylePlain];
    settingTableView.scrollEnabled = NO;
    settingTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    settingTableView.delegate = self;
    settingTableView.dataSource = self;
    [view addSubview:settingTableView];
    
    
    UIButton *quitButton = [[UIButton alloc]initWithFrame:CGRectMake(40 ,view.bottom + 15, kWidth-80, 40)];
    [quitButton setTitle:@"退出登录" forState:UIControlStateNormal];
    [quitButton addTarget:self action:@selector(quitButtonAciton) forControlEvents:UIControlEventTouchUpInside];
    [quitButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [quitButton setBackgroundImage:[UIImage imageNamed:@"register_login"] forState:UIControlStateNormal];
    [self.view addSubview:quitButton];
    
    // Do any additional setup after loading the view.
}


-(void)quitButtonAciton{
    
    APP_DELEGATE.isLogin = NO;
   [APP_DELEGATE pushLoginViewControllerWithStoryBoardIdentifier:@"LoginViewController" pushIn:self];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    ;
}


- (void)viewWillDisappear:(BOOL)animated
{
    
    [super viewWillDisappear:animated];
    
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return _dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    int row = indexPath.row;
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SettingIdentitfer"];
    
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SettingIdentitfer"];
    if (indexPath.row != 0) {
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
    
    switch (row) {
        case 0:
        {
            cell.textLabel.text = _dataArray[0];
        
            UISwitch *oauthSwitch = nil;
            oauthSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(0, 10, 40, 20)];
            oauthSwitch.center = CGPointMake(settingTableView.bounds.size.width - 40, oauthSwitch.center.y);
             [oauthSwitch addTarget:self action:@selector(onSwitchOauth:) forControlEvents:UIControlEventValueChanged];
            [cell addSubview:oauthSwitch];
            oauthSwitch.onTintColor = MAIN_ORANGE_COLOR;
            
            UILabel *seperateLabel = [[UILabel alloc]init];
            seperateLabel.frame = CGRectMake(0,50 - 1, kWidth, 1);
            seperateLabel.backgroundColor = UIColorFromRGB(0x9fa0a0);
            [cell addSubview:seperateLabel];
        }
            break;
        case 1:
        {
            cell.textLabel.text = _dataArray[1];
            
            UILabel *seperateLabel = [[UILabel alloc]init];
            seperateLabel.frame = CGRectMake(0,50 - 1, kWidth, 1);
            seperateLabel.backgroundColor = UIColorFromRGB(0x9fa0a0);
            [cell addSubview:seperateLabel];
        break;
    }
        default:
            break;
    }
    return cell;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    int row = indexPath.row;
//    if (row == 1) {
//       //欢迎页
//    
//    }else
        if (row == 1){
        AboutViewController *aboutVC = [[AboutViewController alloc]initWithNibName:@"AboutViewController" bundle:nil];
            aboutVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:aboutVC animated:YES];
        
//        //用后感
//        ReadingViewController *readVC = [[NSBundle mainBundle]loadNibNamed:@"ReadingViewController" owner:self options:nil][0];
//        [self.navigationController pushViewController:readVC animated:YES];
//        
//    }else if (row == 3){
//        //支付帮助
//      
//        
//    }else if (row == 4){
          //关于
    }
}

-(void)onSwitchOauth:(UISwitch *)switcher
{
    
    
    if (switcher.isOn == YES) {
        NSLog(@"打开");
    }else{
        NSLog(@"关闭");
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
